<template>
	 <div class="JNPF-common-layout">
		 <div class="JNPF-common-layout-center">
			<div class="JNPF-common-layout-main JNPF-flex-main">
				<div class="JNPF-common-head">
					<div>
						<el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()">
							新增
						</el-button>
						<el-button type="text" icon="el-icon-download" @click="exportData()">
							导出
						</el-button>
					</div>
					<div class="JNPF-common-head-right">
						<el-tooltip effect="dark" content="刷新" placement="top">
							<el-link icon="icon-ym icon-ym-Refresh JNPF-common-head-icon" :underline="false"  @click="reset()" />
						</el-tooltip>
						<screenfull :isContainer="true" />
						<el-tooltip effect="dark" content="列设置" placement="top">
							<el-link icon="icon-ym icon-ym-options JNPF-common-head-icon" :underline="false" />
						</el-tooltip>
					</div>
				</div>
				<JNPF-table v-loading="listLoading" :data="list">
					<el-table-column prop="cnkbh" width="90px" label="承诺卡编号" align="left" />
					<el-table-column label="承诺人"  prop="cnr" algin="left">
						<template slot-scope="scope">{{ scope.row.cnr | dynamicText(cnrOptions) }}</template>
					</el-table-column>
					<el-table-column prop="cnrq" label="承诺日期" align="left" />
					<el-table-column prop="tjdh" width="100px" label="特级动火数量" align="left" />
					<el-table-column prop="ejdh" width="100px" label="二级动火数量" align="left" />
					<el-table-column prop="mbcd" width="100px" label="盲板抽堵数量" align="left" />
					<el-table-column prop="dzsl" label="吊装数量" align="left" />
					<el-table-column prop="dtsl" label="动土数量" align="left" />
					<el-table-column prop="jwx" width="90px" label="检维修数量" align="left" />
					<el-table-column prop="sczz" width="100px" label="生产装置套数" align="left" />
					<el-table-column prop="tcts" label="停车套数" align="left" />
					<el-table-column label="是否有承包商作业" width="120px" prop="sfcbs" algin="left">
						<template slot-scope="scope">{{ scope.row.sfcbs | dynamicText(sfcbsOptions) }}</template>
					</el-table-column>
					<el-table-column label="是否有开停车" width="100px" prop="sfkc" algin="left">
						<template slot-scope="scope">{{ scope.row.sfkc | dynamicText(sfkcOptions) }}</template>
					</el-table-column>
					<el-table-column label="是否有承包商作业（扩试）" width="170px" prop="sfkzz" algin="left">
						<template slot-scope="scope">{{ scope.row.sfkzz | dynamicText(sfkzzOptions) }}</template>
					</el-table-column>
					<el-table-column prop="yjdh" width="100px" label="一级动火数量" align="left" />
					<el-table-column prop="sxkj" width="100px" label="受限空间数量" align="left" />
					<el-table-column prop="gczy" width="100px" label="高处作业数量" align="left" />
					<el-table-column prop="lsyd" width="100px" label="临时用电数量" align="left" />
					<el-table-column prop="dlsl" label="断路数量" align="left" />
					<el-table-column prop="dhsl" label="动火数量" align="left" />
					<el-table-column prop="yxts" label="运行套数" align="left" />
					<el-table-column label="是否有试生产" width="100px" prop="sfssc" algin="left">
						<template slot-scope="scope">{{ scope.row.sfssc | dynamicText(sfsscOptions) }}</template>
					</el-table-column>
					<el-table-column label="是否有重大隐患" width="110px" prop="sfzdyh" algin="left">
						<template slot-scope="scope">{{ scope.row.sfzdyh | dynamicText(sfzdyhOptions) }}</template>
					</el-table-column>
					<el-table-column label="风险等级"  prop="fxdj" algin="left">
						<template slot-scope="scope">{{ scope.row.fxdj | dynamicText(fxdjOptions) }}</template>
					</el-table-column>
					<el-table-column label="操作" fixed="right" width="150">
						<template slot-scope="scope">
							<el-button type="text" @click="addOrUpdateHandle(scope.row.id)" >
								编辑
							</el-button>
							<el-button type="text" @click="handleDel(scope.row.id)" class="JNPF-table-delBtn">
								删除
							</el-button>
							<el-button type="text" @click="addOrUpdateHandle(scope.row.id,true)" >
								详情
							</el-button>
						</template>
					</el-table-column>
				</JNPF-table>
				<pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
			</div>
		 </div>
		 <JNPF-Form v-if="formVisible" ref="JNPFForm" @refresh="refresh" />
		 <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
	 </div>
</template>

<script>
  import request from '@/utils/request'
	import {getDictionaryDataSelector} from '@/api/systemData/dictionary'
	import JNPFForm from './Form'
	import ExportBox from './ExportBox'
	// import {previewDataInterface} from '@/api/systemData/dataInterface'
export default {
  name:'aqscZrcnk',
	data() {
		return {
			showAll: false,
				defaultProps: {
						children: 'children',
						label: 'fullName'
				},
				list: [],
				listLoading: true,
				total: 0,
				listQuery: {
					currentPage: 1,
					pageSize: 20,
					sort: "desc",
					sidx: "",
				},
				formVisible: false,
				exportBoxVisible: false,
				columnList: [
					{prop: 'cnkbh', label: '承诺卡编号'},
					{prop: 'cnr', label: '承诺人'},
					{prop: 'cnrq', label: '承诺日期'},
					{prop: 'tjdh', label: '特级动火数量'},
					{prop: 'ejdh', label: '二级动火数量'},
					{prop: 'mbcd', label: '盲板抽堵数量'},
					{prop: 'dzsl', label: '吊装数量'},
					{prop: 'dtsl', label: '动土数量'},
					{prop: 'jwx', label: '检维修数量'},
					{prop: 'sczz', label: '生产装置套数'},
					{prop: 'tcts', label: '停车套数'},
					{prop: 'sfcbs', label: '是否有承包商作业'},
					{prop: 'sfkc', label: '是否有开停车'},
					{prop: 'sfkzz', label: '是否有承包商作业（扩试）'},
					{prop: 'yjdh', label: '一级动火数量'},
					{prop: 'sxkj', label: '受限空间数量'},
					{prop: 'gczy', label: '高处作业数量'},
					{prop: 'lsyd', label: '临时用电数量'},
					{prop: 'dlsl', label: '断路数量'},
					{prop: 'dhsl', label: '动火数量'},
					{prop: 'yxts', label: '运行套数'},
					{prop: 'sfssc', label: '是否有试生产'},
					{prop: 'sfzdyh', label: '是否有重大隐患'},
					{prop: 'fxdj', label: '风险等级'},
				],
				cnrOptions:[],
				sfcbsOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfkcOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfkzzOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfsscOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				sfzdyhOptions:[{"fullName":"是","id":"1"},{"fullName":"否","id":"2"}],
				fxdjOptions:[{"fullName":"重大风险","id":"1"},{"fullName":"较大风险","id":"2"},{"fullName":"一般风险","id":"3"},{"fullName":"低风险","id":"4"}],
		}
  },
    components: {JNPFForm, ExportBox},
	  created() {
		  this.initData();
	    // this.getcnrOptions();
	  },
		methods: {
			// getcnrOptions(){
			// 	previewDataInterface('8bca424f16d6448ab09e57a028853aa9').then(res => {
			// 		this.cnrOptions = res.data
			// 	})
			// },
			initData() {
				this.listLoading = true;
				let query = {
					...this.listQuery,
					...this.query
				};
				request({
					url: `/api/System/aqscZrcnk`,
					method: 'get',
					data: query
				}).then(res => {
					this.list = res.data.list
					this.total = res.data.pagination.total
					this.listLoading = false
					this.$nextTick(() => {
							this.tableHeight = "100%"
					});
				})
			},
			handleDel(id) {
				this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
					type: 'warning'
				}).then(() => {
					request({
						url: `/api/System/aqscZrcnk/${id}`,
						method: 'DELETE'
					}).then(res => {
						this.$message({
							type: 'success',
							message: res.msg,
							onClose: () => {
									this.initData()
							}
						});
					})
				}).catch(() => {
				});
			},
			addOrUpdateHandle(id,isDetail) {
				this.formVisible = true
				this.$nextTick(() => {
					this.$refs.JNPFForm.init(id,isDetail)
				})
			},
			exportData() {
				this.exportBoxVisible = true
				this.$nextTick(() => {
						this.$refs.ExportBox.init(this.columnList)
				})
			},
			download(data) {
				let query = {...data, ...this.listQuery, ...this.query}
				request({
					url: `/api/System/aqscZrcnk/Actions/Export`,
					method: 'POST',
					data: query
				}).then(res => {
					if (!res.data.url) return
					window.location.href = this.define.comUrl + res.data.url
					this.$refs.ExportBox.visible = false
					this.exportBoxVisible = false
				})
			},
			search() {
				this.listQuery = {
				currentPage: 1,
				pageSize: 20,
				sort: "desc",
				sidx: "",
			}
				this.initData()
			},
			refresh(isrRefresh) {
					this.formVisible = false
					if (isrRefresh) this.reset()
			},
			reset() {
				for (let key in this.query) {
					this.query[key] = undefined
				}
				this.listQuery = {
					currentPage: 1,
					pageSize: 20,
					sort: "desc",
					sidx: "",
				}
				this.initData()
		  }
	}
}
</script>

<style>

</style>